#include <stdlib.h>
#include "list.h"
#include <stdio.h>

void check(bool test) {
	if (!test)
		exit(1);
}

int main() {
	nbds::list<int> l;

	l.push_front(5);

	nbds::list<int>::iterator it = l.begin();
	check(*it == 5);
	it++;
	check(*it == 5);

	l.push_front(8);
	it = l.begin();
	check(*it == 8);
	it++;
	check(*it == 5);
	it++;
	check(*it == 8);
	it--;
	check(*it == 5);
	it--;
	check(*it == 8);

	l.push_back(9);
	l.push_front(1);
	l.push_back(7);
	l.push_front(15);

	it = l.begin();
	check(!it.did_cycle());
	check(it.at_begin());
	check(*it++ == 15);
	check(*it++ == 1);
	check(*it++ == 8);
	check(*it++ == 5);
	check(*it++ == 9);
	check(it.at_end());
	check(*it++ == 7);
	check(it.at_begin());
	check(it.did_cycle());

	it = l.end();
	check(!it.did_cycle());
	check(it.at_end());
	check(*it-- == 7);
	check(*it-- == 9);
	check(*it-- == 5);
	check(*it-- == 8);
	check(*it-- == 1);
	check(it.at_begin());
	check(*it-- == 15);
	check(it.at_end());
	check(it.did_cycle());
}
